﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PipeLinesManager : UnitySingleton<PipeLinesManager> {

	public GameObject Pipeline;
	private List<Pipeline> pipelines = new List<Pipeline> ();
	private Coroutine coroutine=null;
	
	public void Init()
	{
		for (int i=0; i<pipelines.Count; i++) 
		{
			Destroy(pipelines[i].gameObject);
		}
		pipelines.Clear ();
	}

	public void StartPipe()
	{
		Init ();
		coroutine = StartCoroutine (CreatePipelines());
	}

	public void StopPipe()
	{
		for (int i=0; i<pipelines.Count; i++) 
		{
			pipelines[i].enabled=false;
		}
		StopCoroutine (coroutine);
	}

	IEnumerator CreatePipelines()
	{
		for(int i=0;i<3;i++)
		{
			GameObject pipe=Instantiate(Pipeline);
			pipe.transform.SetParent(this.transform);
			Pipeline p=pipe.GetComponent<Pipeline>();
			pipelines.Add(p);
			yield return new WaitForSeconds(1.5f);
		}
	}
}
